﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityLayer;
using DataLayer.EF;
namespace DataLayer.CLASES_DAO
{
    public class clsTB_ClienteDAO
    {

        //private BD_TRASNFINTEREntities ContextoDeObjs = new BD_TRASNFINTEREntities();
        public static clsTB_ClienteDAO Instance()
        {
            if (_instance == null)
            {
                lock (typeof(clsTB_ClienteDAO))
                {
                    if (_instance == null)
                    {
                        _instance = new clsTB_ClienteDAO();
                    }
                }
            }
            return _instance;
        }
        protected clsTB_ClienteDAO() { }
        private static volatile clsTB_ClienteDAO _instance = null;
        private BD_TRASNFINTEREntities ContextoDeObjs = new BD_TRASNFINTEREntities();
        public bool Insertar(TB_Cliente Obj)
        {
            try
            {
                ContextoDeObjs.AddObject("TB_Cliente", Obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
        public bool Modificar(TB_Cliente obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("TB_Cliente", obj);
                ContextoDeObjs.ObjectStateManager.ChangeObjectState(obj, System.Data.EntityState.Modified);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;

            }
            return true;
        }
        public bool Eliminar(TB_Cliente obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("TB_Cliente", obj);
                ContextoDeObjs.DeleteObject(obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
        public List<TB_Cliente> listar()
        {

            List<TB_Cliente> lista = new List<TB_Cliente>();
            try
            {
                var q = from c in ContextoDeObjs.TB_Cliente
                        select c;
                lista = q.ToList();

            }
            catch (Exception)
            {
            }
            return lista;
        }

        public List<TB_Cliente> listarClienteDni(string IdCliente)
        {

            List<TB_Cliente> lista = new List<TB_Cliente>();
            try
            {
                var q = from c in ContextoDeObjs.TB_Cliente
                        where c.idcCliente == IdCliente
                        select c;
                lista = q.ToList();

            }
            catch (Exception)
            {
            }
            return lista;
        }

        public List<TB_Cliente> getNombreCliente(string idCliente)
        {
List<TB_Cliente> lista = new List<TB_Cliente>();
            try
            {

                var q = from c in ContextoDeObjs.TB_Cliente
                        where c.idcCliente == idCliente
                        select c;
                lista = q.ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return lista;
        }
    }
}
